﻿using UnityEngine;
using System.Collections;

public class TextureRenderer : MonoBehaviour {

    CameraFitPixels fit;
    Transform texture;

	// Use this for initialization
	void Start ()
    {
        fit = FindObjectOfType(typeof(CameraFitPixels)) as CameraFitPixels;
        texture = transform.Find("Texture");
	}
	
    [ExecuteInEditMode]
	// Update is called once per frame
	void Update ()
    {
        float width = (Screen.width / fit.zoom) / 2048;
        float height = (Screen.height / fit.zoom) / 2048;
        texture.renderer.material.mainTextureScale = new Vector2(width, height);
        texture.localScale = new Vector3(camera.aspect, camera.orthographicSize * 2, 1);
	}
}
